// var inc = 0;
const app = getApp();
Page({
  data: {
    modal: {
      toastHidden: true,
      msg: "当前网格异常，请稍后再试"
    },
    banners: [],
    indicatorDots: true,//是否显示面板指示点
    vertical: false,
    autoplay: true,
    interval: 2000, //自动切换时间间隔
    duration: 500
  },
  onLoad: function (options) {

  },
  onReady: function () {

  },
  onShow: function () {
    var that = this;
    // banner渲染
    wx.request({
      url: 'https://jgj.hzlingdian.com/busiBanner/find/all',
      method: "GET",
      data: {},
      header: {
        'Content-Type': 'application/json',
      },
      success: function (res) {

        var bannerList = [];
        var res = res.data;
        for (var i = 0; i < res.data.length; i++) {
          bannerList[i] = app.globalData.publicUrl + 'coreAttachment/image/get/' + res.data[i].bsbarPic;
        }
        that.setData({ "banners": bannerList });
      },
      fail: function (res) {
        let toastHidden = modal.toastHidden;
        let msg = modal.msg;
        that.setData({ [toastHidden]: false, [msg]: '当前网格异常，请稍后再试' });
      }
    })
  },
  onHide: function () {
  },
  changeIndicatorDots: function (e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function (e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function (e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function (e) {
    this.setData({
      duration: e.detail.value
    })
  },
  toastChange() {
    this.setData({
      duration: e.detail.value
    })
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  }
  // getUserInfo: function (e) {
  //   app.globalData.userInfo = e.detail.userInfo
  //   this.setData({
  //     userInfo: e.detail.userInfo,
  //     hasUserInfo: true
  //   })
  // }
})
